<?php
// 系统配置API测试文件
// 用于小程序启动时获取系统配置信息

// 设置响应头
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');

// 处理OPTIONS预检请求
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
    http_response_code(200);
    exit();
}

// 检查action参数
$action = $_GET['action'] ?? '';

if ($action !== 'config') {
    http_response_code(400);
    echo json_encode([
        'code' => 400,
        'success' => false,
        'message' => '无效的action参数',
        'data' => null,
        'timestamp' => time()
    ], JSON_UNESCAPED_UNICODE);
    exit();
}

// 系统配置数据
$systemConfig = [
    // 营业时间配置
    'openingHours' => [
        'weekdays' => '09:00-17:00',
        'weekends' => '09:00-18:00',
        'holidays' => '10:00-16:00'
    ],
    
    // 预约规则配置
    'reservationRules' => [
        'maxAdvanceDays' => 30,
        'minAdvanceHours' => 2,
        'maxPersonalVisitors' => 6,
        'maxTeamSize' => 50,
        'timeSlots' => ['09:00', '10:00', '14:00', '15:00']
    ],
    
    // 系统维护状态
    'maintenance' => [
        'isEnabled' => false,
        'message' => '',
        'startTime' => null,
        'endTime' => null
    ],
    
    // 功能开关配置
    'features' => [
        'personalReservation' => true,
        'teamReservation' => true,
        'activityApplication' => true,
        'volunteerApplication' => true,
        'onlinePayment' => false
    ],
    
    // 联系信息配置
    'contact' => [
        'phone' => '400-123-4567',
        'email' => 'info@museum.com',
        'address' => '博物馆地址',
        'workingHours' => '周一至周日 9:00-17:00'
    ],
    
    // 版本控制配置
    'version' => [
        'minVersion' => '1.0.0',
        'latestVersion' => '1.2.0',
        'forceUpdate' => false,
        'updateMessage' => '发现新版本，建议更新以获得更好体验'
    ],
    
    // 其他配置
    'other' => [
        'maxFileSize' => 2048, // KB
        'allowedImageTypes' => ['jpg', 'jpeg', 'png', 'gif'],
        'defaultAvatar' => '/images/default-avatar.png',
        'pageSize' => 10
    ]
];

// 返回成功响应
http_response_code(200);
echo json_encode([
    'code' => 200,
    'success' => true,
    'message' => '获取配置成功',
    'data' => $systemConfig,
    'timestamp' => time()
], JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

?>